﻿using GN.Pay.Client.Commands;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;

namespace GN.Pay.Client
{
    class Program
    {
        private readonly static LinkedList<ICommand> commands;

        static Program()
        {
            commands = ACommand.Commands();
        }

        static void Main(string[] args)
        {
            Console.Title = "贵农支付系统客户端命令工具";
            while (true)
            {
                try
                {
                    Console.Write(">");
                    string cmdArgs = Console.ReadLine();
                    if (!string.IsNullOrWhiteSpace(cmdArgs))
                    {
                        var cmd = commands.First;
                        if (cmd != null)
                        {
                            while (!cmd.Value.SendCommand(cmdArgs))
                            {
                                cmd = cmd.Next;
                                if (cmd == null)
                                {
                                    NonSupportCommand();
                                    break;
                                }
                            }
                        }
                        else
                        {
                            NonSupportCommand();
                        }
                    }
                }
                catch (Exception err)
                {
                    ConsoleUtils.WriteError(err.Message);
                }
                Console.WriteLine();
            }
        }

        private static void NonSupportCommand()
        {
            Console.WriteLine("不支持的命令");
        }
    }
}
